package recommenRatings.domain;

import java.util.ArrayList;
import java.util.Collection;

import recommenRatings.data.JDBCPlaceDAO;

public class PlaceManager {

	private Collection<Place> place;

	public PlaceManager() {

		place = this.searchAll();

	}

	public PlaceManager(String name) {

		place = this.searchByName(name);
	}

	public PlaceManager(String city, String state, String type, String subType) {

		place = this.advancedSearch(city, state, type, subType);

	}

	public void setPlace(Collection<Place> place) {
		this.place = place;
	}

	public Collection<Place> getPlace() {
		return place;
	}

	public boolean addPlace() {
		return false;

	}

	public Collection<Place> searchAll() {

		return (new JDBCPlaceDAO()).select("");
	}

	public Collection<Place> searchByName(String name) {

		String stmt = " WHERE name LIKE '%" + name + "%'";
		return (new JDBCPlaceDAO()).select(stmt);

	}

	public Collection<Place> advancedSearch(String city, String state,
			String type, String subType) {
		String stmt = " WHERE city ='" + city + "' AND state ='" + state
				+ "' AND type ='" + type + "' AND subType ='" + subType + "'";
		return (new JDBCPlaceDAO()).select(stmt);

	}

	public Place getPlace(String placeID) {
		Place result = null;
		for (Place p : place) {

			if (p.getPlaceID().compareTo(placeID) == 0) {
				result = p;
			}
		}
		return result;

	}

	public Collection<String> stateFilter() {

		Collection<String> result = new ArrayList<String>();
		for (Place p : place) {
			String s = p.getState();
			if (!result.contains(s)) {
				result.add(s);
			}
		}
		return result;
	}

	public Collection<String> cityFilter() {

		Collection<String> result = new ArrayList<String>();
		for (Place p : place) {
			String s = p.getCity();
			if (!result.contains(s)) {
				result.add(s);
			}
		}
		return result;

	}

	public Collection<String> typeFilter() {

		Collection<String> result = new ArrayList<String>();
		for (Place p : place) {
			String s = p.getType();
			if (!result.contains(s)) {
				result.add(s);
			}
		}
		return result;
	}

	public Collection<String> subtypeFilter() {

		Collection<String> result = new ArrayList<String>();
		for (Place p : place) {
			String s = p.getSubType();
			if (!result.contains(s)) {
				result.add(s);
			}
		}
		return result;
	}

	public void priceFilter() {

	}
}
